package com.ea.eadp.nexus.test.pageDefinition.originX;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;

import com.ea.eadp.nexus.test.common.PageOperation;
import com.ea.eadp.nexus.test.pageDefinition.BasePage;

public class CompleteAccountPage extends BasePage {
    private static final String TITLE_ID = "upgradeForm";
    private static final String ID_ID = "originId";
    private static final String FISRTNAME_ID = "firstName";
    private static final String LASTNAME_ID = "lastName";

    private static final String NEXT_BUTTON_ID = "updateBtn";
    private static final String MISS_ID_ID = "form-error-missing-originId";
    private static final String TOO_SHORT_ID_ID = "form-error-origin-id-too-short";
    private static final String TOO_LONG_ID_ID = "form-error-origin-id-too-long";
    private static final String INVALID_ID_ID = "form-error-origin-id-too-long";
    private static final String DUPLICATED_ID_ID = "form-error-origin-id-duplicate";

    private static final String MISS_ID_MESSAGE = "Missing ID";
    private static final String TOO_SHORT_ID_MESSAGE = "ID must be between 4 and 16 characters.";
    private static final String TOO_LONG_ID_MESSAGE = "ID must be between 4 and 16 characters.";
    private static final String INVALID_ID_MESSAGE = "ID contains a prohibited word or character";
    private static final String DUPLICATED_ID_MESSAGE = "ID has already been registered";

    public CompleteAccountPage(WebDriver driver) {
        super(driver, CompleteAccountPage.class);
    }

    public void waitPageLoadCompleted() {
        PageOperation.WebDriverWait(driver, TITLE_ID);
    }

    public void inputId(final String Id) {
        PageOperation.SendKeyToElementAfterWait(driver, ID_ID, Id);
    }

    public void inputFirstName(final String firstName) {
        PageOperation.SendKeyToElementAfterWait(driver, FISRTNAME_ID, firstName);
    }

    public void inputLastName(final String lastName) {
        PageOperation.SendKeyToElementAfterWait(driver, LASTNAME_ID, lastName);
    }

    public void validateNextButtonIsDisabled() {
        Assert.assertTrue(driver.findElement(By.id(NEXT_BUTTON_ID)).getAttribute("class").contains("disabled"));
    }

    public void clickNextButton() {
        driver.findElement(By.id(NEXT_BUTTON_ID)).click();
    }

    public void validateMissId() {
        validateErrorMassage(MISS_ID_ID, MISS_ID_MESSAGE);
    }

    public void validateTooShortId() {
        validateErrorMassage(TOO_SHORT_ID_ID, TOO_SHORT_ID_MESSAGE);
    }

    public void validateTooLongId() {
        validateErrorMassage(TOO_LONG_ID_ID, TOO_LONG_ID_MESSAGE);
    }

    public void validateInvalidId() {
        validateErrorMassage(INVALID_ID_ID, INVALID_ID_MESSAGE);
    }

    public void validateDuplicatedId() {
        validateErrorMassage(DUPLICATED_ID_ID, DUPLICATED_ID_MESSAGE);
    }
}
